/*
 * main.cpp
 *
 *  Created on: 2011-9-30
 *      Author: shenjiong
 */

#include "ProtoFile.h"
#include "buffclass.h"
#include "sndarecord.pb.h"
#include "ReadRawFile.h"
#include "Disktools.h"
#include "SortFun.h"
#include <stdlib.h>
#include <stdio.h>
#include "operationfun.h"
#include "saft_deque.h"
#include "SortFun.h"
#include "showrecord.h"
#include "cleanindex.h"
#include "count.h"
#include "merghashcode.h"
#include "testhash.h"
#include "conver.h"

mutex_block split_lock;
int needsplit;
int splited;
saft_deque<splittxtfilearg> request_splittxtfilearg;

int main(int argc, char * argv[])
{

    std::string disk;
    std::string result;
    std::string method;
    if(argc != 4)
    {
        printf("merg disk result\n");
        return 0;
    }

    method = argv[1];
    disk = argv[2];
    result = argv[3];
    
    if(method == "sort")
    {
        SortTxtFile5<keybaserecord, operation_keybaserecord_bykey>(disk, result,
                5 * 1024 * 20);
    }
    else if(method == "show")
    {
        ShowResult<keybaserecord, showrecord>(disk);
    }
    else if(method == "clean")
    {
        cleanindex<keybaserecord, euqalrecord, DelMarkereuqal>(disk, result);
    }
    else if(method == "count")
    {
        long long x = 0;
        getcount<keybaserecord>(disk, x);
        std::cout << "" << x << std::endl;
        
    }
    else if(method == "countdisk")
    {
        long long x;
        getcountdisk<keybaserecord>(disk, x);
        std::cout << "" << x << std::endl;
        
    }else if (method == "hash")
    {
        testhashcode<keybaserecord>(disk, 32);
    } else if (method == "conver")
    {
        converfile<keybaserecord>(disk, result);
    }
    return 0;
}

